"""
确认对话框
"""

from PyQt5.QtWidgets import (
    QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton,
    QFrame
)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont

class ConfirmDialog(QDialog):
    """确认对话框"""
    
    def __init__(self, title="确认", message="确定要执行此操作吗？", parent=None):
        super().__init__(parent)
        
        self.setWindowTitle(f"❓ {title}")
        self.setFixedSize(400, 200)
        self.setModal(True)
        
        self.message = message
        self.result = False
        
        self.setup_ui()
        self.setup_style()
    
    def setup_ui(self):
        """设置用户界面"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(16)
        
        # 图标和消息
        message_layout = QHBoxLayout()
        message_layout.setAlignment(Qt.AlignCenter)
        
        # 图标
        icon_label = QLabel("❓")
        icon_label.setFont(QFont("Microsoft YaHei", 32))
        message_layout.addWidget(icon_label)
        
        # 消息文本
        message_label = QLabel(self.message)
        message_label.setFont(QFont("Microsoft YaHei", 10))
        message_label.setWordWrap(True)
        message_label.setAlignment(Qt.AlignCenter)
        message_label.setStyleSheet("color: #333333; line-height: 1.5; padding: 0 10px;")
        message_layout.addWidget(message_label)
        
        layout.addLayout(message_layout)
        
        # 分隔线
        separator = QFrame()
        separator.setFrameShape(QFrame.HLine)
        separator.setStyleSheet("color: #e0e0e0; margin: 10px 0;")
        layout.addWidget(separator)
        
        # 按钮区域
        button_layout = QHBoxLayout()
        button_layout.addStretch()
        
        # 取消按钮
        cancel_button = QPushButton("取消")
        cancel_button.setFixedSize(80, 32)
        cancel_button.clicked.connect(self.reject)
        button_layout.addWidget(cancel_button)
        
        # 确定按钮
        ok_button = QPushButton("确定")
        ok_button.setFixedSize(80, 32)
        ok_button.clicked.connect(self.accept)
        button_layout.addWidget(ok_button)
        
        layout.addLayout(button_layout)
    
    def setup_style(self):
        """设置样式"""
        self.setStyleSheet("""
            QDialog {
                background-color: #ffffff;
            }
            QPushButton {
                border: 1px solid #e0e0e0;
                border-radius: 4px;
                padding: 6px 12px;
                font-weight: bold;
            }
            QPushButton[text="确定"] {
                background-color: #1976d2;
                color: white;
                border: none;
            }
            QPushButton[text="确定"]:hover {
                background-color: #1565c0;
            }
            QPushButton[text="确定"]:pressed {
                background-color: #0d47a1;
            }
            QPushButton[text="取消"]:hover {
                background-color: #f5f5f5;
            }
            QPushButton[text="取消"]:pressed {
                background-color: #e0e0e0;
            }
        """)

class WarningDialog(ConfirmDialog):
    """警告对话框"""
    
    def __init__(self, title="警告", message="注意：此操作可能存在风险！", parent=None):
        super().__init__(title, message, parent)
        self.setWindowTitle(f"⚠️ {title}")
    
    def setup_ui(self):
        """设置用户界面"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(16)
        
        # 图标和消息
        message_layout = QHBoxLayout()
        message_layout.setAlignment(Qt.AlignCenter)
        
        # 图标
        icon_label = QLabel("⚠️")
        icon_label.setFont(QFont("Microsoft YaHei", 32))
        icon_label.setStyleSheet("color: #ff9800;")
        message_layout.addWidget(icon_label)
        
        # 消息文本
        message_label = QLabel(self.message)
        message_label.setFont(QFont("Microsoft YaHei", 10))
        message_label.setWordWrap(True)
        message_label.setAlignment(Qt.AlignCenter)
        message_label.setStyleSheet("color: #333333; line-height: 1.5; padding: 0 10px;")
        message_layout.addWidget(message_label)
        
        layout.addLayout(message_layout)
        
        # 分隔线
        separator = QFrame()
        separator.setFrameShape(QFrame.HLine)
        separator.setStyleSheet("color: #e0e0e0; margin: 10px 0;")
        layout.addWidget(separator)
        
        # 按钮区域
        button_layout = QHBoxLayout()
        button_layout.addStretch()
        
        # 取消按钮
        cancel_button = QPushButton("取消")
        cancel_button.setFixedSize(80, 32)
        cancel_button.clicked.connect(self.reject)
        button_layout.addWidget(cancel_button)
        
        # 确定按钮
        ok_button = QPushButton("继续")
        ok_button.setFixedSize(80, 32)
        ok_button.clicked.connect(self.accept)
        button_layout.addWidget(ok_button)
        
        layout.addLayout(button_layout)

class ErrorDialog(ConfirmDialog):
    """错误对话框"""
    
    def __init__(self, title="错误", message="操作失败，请检查输入！", parent=None):
        super().__init__(title, message, parent)
        self.setWindowTitle(f"❌ {title}")
    
    def setup_ui(self):
        """设置用户界面"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(16)
        
        # 图标和消息
        message_layout = QHBoxLayout()
        message_layout.setAlignment(Qt.AlignCenter)
        
        # 图标
        icon_label = QLabel("❌")
        icon_label.setFont(QFont("Microsoft YaHei", 32))
        icon_label.setStyleSheet("color: #f44336;")
        message_layout.addWidget(icon_label)
        
        # 消息文本
        message_label = QLabel(self.message)
        message_label.setFont(QFont("Microsoft YaHei", 10))
        message_label.setWordWrap(True)
        message_label.setAlignment(Qt.AlignCenter)
        message_label.setStyleSheet("color: #333333; line-height: 1.5; padding: 0 10px;")
        message_layout.addWidget(message_label)
        
        layout.addLayout(message_layout)
        
        # 分隔线
        separator = QFrame()
        separator.setFrameShape(QFrame.HLine)
        separator.setStyleSheet("color: #e0e0e0; margin: 10px 0;")
        layout.addWidget(separator)
        
        # 按钮区域
        button_layout = QHBoxLayout()
        button_layout.addStretch()
        
        # 确定按钮
        ok_button = QPushButton("确定")
        ok_button.setFixedSize(80, 32)
        ok_button.clicked.connect(self.accept)
        button_layout.addWidget(ok_button)
        
        layout.addLayout(button_layout)

class InfoDialog(ConfirmDialog):
    """信息对话框"""
    
    def __init__(self, title="信息", message="操作已完成！", parent=None):
        super().__init__(title, message, parent)
        self.setWindowTitle(f"ℹ️ {title}")
    
    def setup_ui(self):
        """设置用户界面"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(16)
        
        # 图标和消息
        message_layout = QHBoxLayout()
        message_layout.setAlignment(Qt.AlignCenter)
        
        # 图标
        icon_label = QLabel("ℹ️")
        icon_label.setFont(QFont("Microsoft YaHei", 32))
        icon_label.setStyleSheet("color: #2196f3;")
        message_layout.addWidget(icon_label)
        
        # 消息文本
        message_label = QLabel(self.message)
        message_label.setFont(QFont("Microsoft YaHei", 10))
        message_label.setWordWrap(True)
        message_label.setAlignment(Qt.AlignCenter)
        message_label.setStyleSheet("color: #333333; line-height: 1.5; padding: 0 10px;")
        message_layout.addWidget(message_label)
        
        layout.addLayout(message_layout)
        
        # 分隔线
        separator = QFrame()
        separator.setFrameShape(QFrame.HLine)
        separator.setStyleSheet("color: #e0e0e0; margin: 10px 0;")
        layout.addWidget(separator)
        
        # 按钮区域
        button_layout = QHBoxLayout()
        button_layout.addStretch()
        
        # 确定按钮
        ok_button = QPushButton("确定")
        ok_button.setFixedSize(80, 32)
        ok_button.clicked.connect(self.accept)
        button_layout.addWidget(ok_button)
        
        layout.addLayout(button_layout)